<template>
	<view class="help-container">

		<view class="subsection">
			<view class="item  " @click="changeType('new')" :class="{'active': currentType==='new' }">
				<view class="num">{{newOrderList.length}}</view>
				<view class="text">最新推荐</view>
			</view>
			<view class="item" @click="changeType('helping')" :class="{'active': currentType==='helping' }">
				<view class="num">{{myHelpingOrderList.length}}</view>
				<view class="text">已接帮忙</view>
			</view>
			<view class="item" @click="changeType('lost')" :class="{'active': currentType==='lost' }">
				<view class="num">{{lostHelpOrderList.length}}</view>
				<view class="text">错失帮忙</view>
			</view>

		</view>

		<view class="card-list" v-if="currentType==='new'">
			<view class="order-card" v-for="(item,index) in newOrderList" :key="index">
				<orderCard :orderInfo="item"></orderCard>
			</view>
			<emptyData v-if="!newOrderList.length" :tip="'暂无推荐'"> </emptyData>
		</view>

		<view class="card-list" v-if="currentType==='helping'">
			<view class="order-card" v-for="(item,index) in myHelpingOrderList" :key="index">
				<orderCard :orderInfo="item"></orderCard>
			</view>
			<emptyData v-if="!myHelpingOrderList.length" :tip="'暂无帮忙'"></emptyData>
		</view>
		<view class="card-list" v-if="currentType==='lost'">
			<view class="order-card" v-for="(item,index) in lostHelpOrderList" :key="index">
				<orderCard :orderInfo="item"></orderCard>
			</view>
			<emptyData v-if="!lostHelpOrderList.length" :tip="'暂无数据'"></emptyData>
		</view>
		<view class="find-help" @click="gotoPublishOrder()">
			<img src="../../static/img/publish.png" mode=""></img>
			<text>寻求帮忙</text>
		</view>
		<tabbar :pagePath="'pages/helpSquare/index'"></tabbar>
	</view>
</template>

<script>
	import orderCard from '../../components/orderCard.vue'
	import emptyData from '../../components/emptyData.vue'
	export default {
		components: {
			orderCard,
			emptyData
		},
		data() {
			return {
				currentType: 'new',
				orderList: [],
				// 最新推荐
				newOrderList: [],
				// 已接帮忙
				myHelpingOrderList: [],
				//错失帮忙
				lostHelpOrderList: []
			};
		},
		onLoad() {
			this.getOrder()
		},
		methods: {
			changeType(type) {
				this.currentType = type
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 100,
				});
			},

			gotoPublishOrder() {
				uni.navigateTo({
					url: "/pages/publishOrder/index"
				})
			},
			// 获取帮单信息
			getOrder() {
				this.$http('get', 'api/public/order/list', {
					success: (res) => {
						const userInfo = this.$store.getters?.userInfo?.userInfoDetail || null
						console.log(userInfo)
						this.orderList = res.data

						this.newOrderList = this.orderList.filter(item =>
							Number(item.status) === 0
						)
						this.myHelpingOrderList = this.orderList.filter(item =>
							userInfo ? item.did === userInfo.uid : false
						)
						this.lostHelpOrderList = this.orderList.filter(item =>
							userInfo ? item.did !== userInfo.uid && Number(item.status) !== 0 && item
							.uid !== userInfo.uid : Number(item.status) !== 0
						)
					}
				})
			},
		}
	}

</script>

<style lang="scss">
	.help-container {
		height: 100vh;
		padding: 15px;
	}


	.subsection {
		box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
		border-radius: 8px;
		background: #fff;
		height: 80px;
		display: flex;
		align-items: center;
		position: fixed;
		z-index: 2;
		width: calc(100% - 50px);
		padding: 10px;

		.item {
			flex: 1;
			height: 70px;
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;

			&.active {
				background: rgb(255, 255, 255);
				box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.2);
				border-radius: 8px;

				.text {
					font-weight: 700;
				}
			}

			.num {
				font-size: 18px;
				text-align: center;
				font-weight: 700;
			}

			.text {
				text-align: center;
				font-size: 12px;
				color: rgb(51, 51, 51);
				margin-top: 10px;
			}

			&:nth-child(1) {
				.num {
					color: rgb(254, 185, 58);
				}

			}

			&:nth-child(2) {
				.num {
					color: rgb(101, 132, 247);
				}

			}

			&:nth-child(3) {
				.num {
					color: rgb(245, 63, 63);
				}

			}
		}

	}

	.card-list {
		margin-top: 120px;
		height: calc(100% - 180px);
		overflow: auto;


		.order-card:not(:last-child) {
			margin-bottom: 10px;
		}

		.no-data {
			margin-top: 80px;
		}
	}


	.find-help {
		padding-left: 10px;
		width: 90px;
		height: 38px;
		position: fixed;
		bottom: 80px;
		right: 0;
		color: #fff;
		display: flex;
		background: linear-gradient(135deg, #7676ee 0%, #b064fb 100%);
		box-shadow: 0px 2px 10px #8a70f2;
		border-radius: 20px 0px 0px 20px;
		align-items: center;
		font-size: 14px;

		img {
			margin-right: 8px;
		}
	}

</style>

